<?php
/**
 * Created by PhpStorm.
 * Author: 芸签cms www.yunqiancms.com
 * User: sun
 * Date: 2022/6/30
 * Time: 10:55 AM
 */
namespace app\common\models;

class ThemeFile extends BaseModel
{
    public $table = 'yq_theme_file';
    public $timestamps = true;
    protected $guarded = [''];

    const TYPE_INDEX = 'index';//首页
    const TYPE_ARTICLE_LIST = 'article_list';//文章列表
    const TYPE_ARTICLE_DETAIL = 'article_detail';//文章详情
    const TYPE_IMG_LIST = 'img_list';//图片列表
    const TYPE_IMG_DETAIL = 'img_detail';//图片详情
    const TYPE_VIDEO_LIST = 'video_list';//视频列表
    const TYPE_VIDEO_DETAIL = 'video_detail';//视频详情
    const TYPE_PRODUCT_LIST = 'product_list';//产品列表
    const TYPE_PRODUCT_DETAIL = 'product_detail';//产品详情
    const TYPE_PAGE = 'page';//单页
    const TYPE_LAYOUT = 'layout';//产品详情
    public static $allTypes = [
        self::TYPE_INDEX,
        self::TYPE_ARTICLE_LIST,
        self::TYPE_ARTICLE_DETAIL,
        self::TYPE_IMG_LIST,
        self::TYPE_IMG_DETAIL,
        self::TYPE_VIDEO_LIST,
        self::TYPE_VIDEO_DETAIL,
        self::TYPE_PRODUCT_LIST,
        self::TYPE_PRODUCT_DETAIL,
        self::TYPE_PAGE,
        self::TYPE_LAYOUT,
    ];
    public static function getBaseInfo($id){
        return self::site()->select(['id','site_id','theme_id','name','type','file','description'])
            ->with(['theme' => function($query) {
                return $query->select('id','name','theme','version','type');
            }])
            ->where('id',$id)
            ->first();
    }
    public function theme()
    {
        return $this->hasOne(Theme::class, 'id', 'theme_id');
    }
}